package com.lanchetech.bean.response;

import com.lanchetech.common.enums.ResultCode;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.text.MessageFormat;
import java.util.List;

@Data
public class BaseResp {
    private String reqNo;

    private String code;

    private String message;

    private Object object;

    private List<?> errorCodes;

    public BaseResp() {
        this(ResultCode.SUCCESS);
    }

    public BaseResp(String reqNo) {
        this.reqNo = reqNo;
    }

    public BaseResp(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMsg();
    }

    public BaseResp(String reqNo, ResultCode resultCode) {
        this.reqNo = reqNo;
        this.code = resultCode.getCode();
        this.message = resultCode.getMsg();
    }

    public void setResultCode(ResultCode resultCode, Object... args) {
        this.code = resultCode.getCode();
        this.message = MessageFormat.format(StringUtils.stripToEmpty(resultCode.getMsg()), args);
    }

    public BaseResp(ResultCode resultCode, String msg) {
        this.code = resultCode.getCode();
        this.message = msg;
    }
}
